package com.cx.factoryMethod;

import com.cx.factoryMethod.api.GiveAward;
import com.cx.factoryMethod.constant.AwardEnum;

/**
 * 工厂方法模式
 * 定义一个奖品工厂,根据类型创建对应的奖品实体类
 *
 * @Author:cxy
 * @Date:2022/3/21 21:30
 */
public class AwardFactory {

    public static GiveAward GiveAwardgetAwardImpl(int type) {
        final Class<? extends GiveAward> aClazz = AwardEnum.valueOf(type);
        assert aClazz != null;
        try {
            return aClazz.getDeclaredConstructor().newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
